#include <iostream>
using namespace std;
char pool[105][105];
int n, m;
void dfs(int x, int y);
int main()
{
    //freopen("in.txt", "r", stdin);
    cin >> n >> m;
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            cin >> pool[i][j];
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (pool[i][j] == 'W')
            {
                dfs(i, j);
                ans++;
            }
        }
    }
    printf("%d", ans);
}

void dfs(int x, int y)
{
    if (pool[x][y] == '.')
        return;
    else
    {
        pool[x][y] = '.';
        for (int dx = -1; dx <= 1; dx++)
        {
            for (int dy = -1; dy <= 1; dy++)
            {
                if (x + dx >= 0 && x + dx < n && y + dy >= 0 && y + dy < m)
                {
                    dfs(x + dx, y + dy);
                }
            }
        }
    }
}